package com.sjy.framework;


import java.io.Serializable;

public class ApiResult<T> implements Serializable {

    private static final long serialVersionUID  = -3567746846746L;

    private boolean success = false;

    private CodeNodeError error;

    private String traceId;

    private T data;

    public ApiResult() {
        super();
    }

    public ApiResult(CodeNodeError error) {
        this.success=false;
        this.error = error;
    }

    public static <T> ApiResult<T> buildSuccess(T data){
        ApiResult<T> result = new ApiResult<>();
        result.setSuccess(Boolean.TRUE);
        result.setData(data);
        return result;
    }

    public static <T> ApiResult<T> buildError(CodeNodeError error){
        ApiResult<T> result = new ApiResult<>();
        result.setSuccess(Boolean.FALSE);
        result.setError(error);
        return result;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public CodeNodeError getError() {
        return error;
    }

    public void setError(CodeNodeError error) {
        this.error = error;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
